package com.example.demoserver.controller;

import com.example.demoserver.entity.InteApplog;
import com.example.demoserver.entity.InteGatewaylog;
import com.example.demoserver.service.InteApplogService;
import com.example.demoserver.service.InteGatewaylogService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;


@RestController
@RequestMapping("/gatelog")
@RequiredArgsConstructor
@Component
public class InteGatewaylogController {
    private final InteGatewaylogService inteGatewaylogService;
    @GetMapping("/selectall")
    public List<InteGatewaylog> selectAll () {
        List<InteGatewaylog> list=inteGatewaylogService.selectAll();
        return list;
    }
    public void saveLog(String op,String type,String value){
        InteGatewaylog inteGatewaylog=new InteGatewaylog();
        inteGatewaylog.setHtype(type);
        inteGatewaylog.setLogoperate(op);
        inteGatewaylog.setLogvalue(value);
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String formatted = now.format(formatter);
        inteGatewaylog.setLogvalue(formatted);
        inteGatewaylogService.save(inteGatewaylog);
    }
}
